<?php
class IndexAction extends CommonAction{
    /**
     *默认首页界面 
     */
    public function index() {
        if (isset($_SESSION[C('USER_AUTH_KEY')]))
            $this->display();
        else
            $this->redirect('Public/login');
    }
    
    /**
     *顶部菜单显示 
     */
    public function top(){
        //获取所有顶级栏目
        $list = M('RoleNav')->where('status=1')->field('id,name')->order("sort")->select();
        $this->assign('role_navs', $list);
        $this->display();
    }
    
    /**
     *左侧导航菜单
     * @return type 
     */
    public function left() {
        $id = intval($_REQUEST['id']);
        $menus = array();
        
        //调用公共函数获取菜单
        $menus=get_menu($id);


        $this->assign('menus', $menus);
        unset($menus);
        $this->display();
    }
    
    /**
     *修改密码界面 
     */
    public function password() {
        $id = $_SESSION[C('USER_AUTH_KEY')];
        $admin = D('Admin')->getById($id);
        $this->assign('admin', $admin);
        $this->display();
    }
    
    
    //框架底部
    public function footer() {
        $this->display();
    }
    
    //保存修改密码方法
    public function changePwd() {
        $old_pwd = $_REQUEST['old_pwd'];
        $new_pwd = $_REQUEST['new_pwd'];
        $confirm_pwd = $_REQUEST['confirm_pwd'];

        if ($old_pwd == '')
            $this->error(L('OLD_PWD_REQUIRE'));

        if ($new_pwd == '')
            $this->error(L('NEW_PWD_REQUIRE'));

        if ($new_pwd != $confirm_pwd)
            $this->error(L('CONFIRM_ERROR'));

        $id = $_SESSION[C('USER_AUTH_KEY')];
        $admin = D('Admin')->getById($id);

        $old_pwd = md5($old_pwd);
        if ($old_pwd != $admin['admin_pwd'])
            $this->error(L('OLD_PWD_ERROR'));

        D("Admin")->where('id = ' . $id)->setField('admin_pwd', md5($new_pwd));
        $this->assign('jumpUrl', U('Index/password'));
        $this->success(L('EDIT_SUCCESS'));
    }
}
?>
